pkgname=vdr
pkgver=1.4.7
pkgrel=1
arch=('i686')
pkgdesc="A digital satellite receiver program using Linux and DVB technologies"
url="http://www.cadsoft.de/vdr/"
license=('GPL')
backup=('etc/vdr/sources.conf' 'etc/vdr/runvdr.conf' 'etc/conf.d/vdr')
depends=('gcc' 'libcap' 'libjpeg' 'ncurses')
install=vdr.install
source=(ftp://ftp.cadsoft.de/$pkgname/$pkgname-$pkgver.tar.bz2 \
	vdr-paths.diff runvdr runvdr.conf stopvdr vdr.rc vdr-api.diff \
	vdr-epg-pl.diff vdr-ffdecsa.diff vdr-sc.diff vdr-dvb-subs.diff \
	vdr.conf vdr-ffdecsa-fix.diff vdr-syncearly.diff vdr-rotor.diff)
md5sums=('81be33a0edb93288ca3d235a04107ec4'
         '2d83e0a3a39697f3eda2ac65cd229a3c'
         '90f8db01fc2ff7be48d25f204b264186'
         'ce5ae41c1a10aee80392660f63d3c2b0'
         '09bd4353f60e0ec94430e3b48341b582'
         '742591b798fd834ace82880ce16043cc'
         '5527e2ac593ad8bf7a39356d5494d90e'
         'f804adc8bfc76ef4df2cce7e79c28028'
         '51fb31ef634c917be932955e3f59b843'
         '5cc8c2041ebb0fc014aa4bc853757ea2'
         'e05c72720d5e5c571bf99d2028365c5a'
         'b18e8966eb3f71c04fa39baea72414e2'
         '14bc4f1b7ff602482753713bdb3221aa'
         'bc170285fcc168b11f125198b4be64cb'
         '3a179b75a114d39c94ffaf766c96c9ea')

build() {
  cd $startdir/src/$pkgname-$pkgver
  
  patch -Np1 -i $startdir/src/vdr-paths.diff || return 1
  patch -Np1 -i $startdir/src/vdr-api.diff || return 1
  patch -Np1 -i $startdir/src/vdr-epg-pl.diff || return 1
  patch -Np1 -i $startdir/src/vdr-syncearly.diff || return 1
  patch -Np1 -i $startdir/src/vdr-sc.diff || return 1
  patch -Np1 -i $startdir/src/vdr-ffdecsa.diff || return 1
  patch -Np1 -i $startdir/src/vdr-ffdecsa-fix.diff || return 1
  patch -Np1 -i $startdir/src/vdr-dvb-subs.diff || return 1

  make || return 1
  make plugins || return 1

  # install vdr
  install -d $startdir/pkg/{etc/vdr,usr/{bin,man/man{1,5},include/vdr/libsi,lib/vdr}}
  install -d -m 2775 $startdir/pkg/var/lib/vdr
  install vdr epg2html.pl svdrpsend.pl $startdir/pkg/usr/bin
  install -m 644 vdr.1 $startdir/pkg/usr/man/man1
  install -m 644 vdr.5 $startdir/pkg/usr/man/man5/vdr.conf.5
  install -m 644 *.conf $startdir/pkg/etc/vdr
  install -m 644 *.h Make.config $startdir/pkg/usr/include/vdr
  install -m 644 libsi/*.h $startdir/pkg/usr/include/vdr/libsi
  install -m 755 PLUGINS/lib/* $startdir/pkg/usr/lib/vdr

  # force users to write their own configuration files
  for i in $startdir/pkg/etc/vdr/*.conf; do
    mv $i $i.example
  done
  # except sources.conf
  mv $startdir/pkg/etc/vdr/sources.conf{.example,}

  # install startup scripts
  install -m 755 $startdir/src/runvdr $startdir/pkg/usr/bin
  install -m 755 $startdir/src/stopvdr $startdir/pkg/usr/bin
  install -m 644 $startdir/src/runvdr.conf $startdir/pkg/etc/vdr
  install -m 644 $startdir/src/runvdr.conf $startdir/pkg/etc/vdr/runvdr.conf.example
  install -m 755 -d $startdir/pkg/etc/rc.d
  install -m 755 $startdir/src/vdr.rc $startdir/pkg/etc/rc.d/vdr
  install -m 644 -D $startdir/src/vdr.conf $startdir/pkg/etc/conf.d/vdr
}
